<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>批注记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-table
            :data="arryList"
            border
            :height="tableHeight"
            style="width: 100%">
          <el-table-column
              prop="create_time"
              label="批注时间"
              align="center"
              width="160">
          </el-table-column>
          <el-table-column
              label="批注人"
              align="center">
            <template slot-scope="scope">
              {{ scope.row.user ? scope.row.user.realname : '' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="remark"
              label="批注内容"
              align="center">
          </el-table-column>
          <el-table-column
              label="批注附件"
              align="center"
              width="100">
            <template slot-scope="scope">
              <el-popover
                  placement="left-start"
                  title=""
                  width="300"
                  trigger="click"
                  v-if="scope.row.file.length">
                <div class="remark">
                  <div>
                    <div>
                      <div v-for="(item, index) in scope.row.file">
                        附件{{index+1}}:<btn_file :option="item"></btn_file>
                      </div>
                    </div>
                  </div>
                </div>
                <span slot="reference" class="tablelineBtn">查看附件</span>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
              label="状态"
              align="center"
              width="80">
            <template slot-scope="scope">
              <el-link type="success" v-if="scope.row.status==1">已处理</el-link>
              <el-link type="danger" v-else>未处理</el-link>
            </template>
          </el-table-column>
          <!--          <el-table-column-->
          <!--              label="操作"-->
          <!--              align="center"-->
          <!--              width="100">-->
          <!--            <template slot-scope="scope">-->
          <!--              <el-button type="danger" size="small" plain @click="handleDetel(scope.row.id)">-->
          <!--                删除-->
          <!--              </el-button>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              layout="prev, pager, next"
              :total="page.total"
              :page-size="page.pagesize"
              @current-change="handleSizeChange">
          </el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
      </div>
    </div>
    <remarkFile :visible.sync="remarkVisible" :noteId="noteId" @getFileListFn="getFileListFn"
                :noteRemark="noteRemark"></remarkFile>
  </div>
</template>

<script>
import {inteactionLogList, noteListDelete, noteLogList} from "@/api/admin/outineWorke"
import {pagination} from '@/utils/util.js'
import remarkFile from "./remarkFile";

export default {
  props: ['visible', 'fileId', 'remarkType'], // commoent 学生点评 collection 学生采集
  components: {
    remarkFile
  },
  data() {
    return {
      dialogVisible: false,
      editStatus: true,
      remarkVisible: false,
      arryList: [],
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      noteId: 0,
      noteRemark: '',
      tableHeight: 0
    }
  },
  watch: {
    visible() {
      let n = this
      this.dialogVisible = this.visible
      if (this.visible) {
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          n.tableHeight = height - (51 + 20 + 50 + 51)
        })
        this.getFileListFn()
      } else {
        this.editForm = {
          evaluation: '',
          strategy: '',
          share: ''
        }
        this.arryList = []
      }
    }
  },
  created() {
  },
  methods: {
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 获取记录
    getFileListFn() {
      if(Number(this.remarkType)===2) {
        noteLogList({p: this.page.pageindex, routine_id: this.fileId}).then(res => {
          for (let item of res.list.data) {
            item.file = JSON.parse(item.file)
          }
          this.arryList = res.list.data
          this.page.total = res.list.total
        })
      }else{
        inteactionLogList({p: this.page.pageindex, routine_id: this.fileId}).then(res => {
          for (let item of res.list.data) {
            if(item.file){
              item.file = JSON.parse(item.file)
            }
          }
          this.arryList = res.list.data
          this.page.total = res.list.total
        })
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    handleDetel(id) {
      this.$confirm('确认删除该工作记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(id)
      }).catch(() => {
      })
    },
    detelRespon(id) {
      noteListDelete({id: id}).then(res => {
        if (!res.code) {
          this.$message.success(res.msg)
          this.getFileListFn()
        }
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 60%;
  height: 650px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.remarkBody {
  white-space: pre-wrap
}
</style>


